<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ include file="../common.inc" %>    
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%java.util.Random r=new java.util.Random();  %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<link href="./css/style1.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="./js/calendar.js"></script>
<script type="text/javascript" src="./js/form.js"></script>
<script type="text/javascript" language="javascript">
<!--
	function checkForm(){
		var subject = document.getElementById("subject");
		var linkman = document.getElementById("linkman");
		var contactWayId = document.getElementById("contactWayId");
		var contactDate = document.getElementById("contactDate");
		var contactTime = document.getElementById("contactTime");
		var nextContactDate = document.getElementById("nextContactDate");
		var nextContactTime = document.getElementById("nextContactTime");
		var requireDesc = document.getElementById("requireDesc");
		var currentDate = document.getElementById("currentDate");
		var nextContactWayId = document.getElementById("nextContactWayId");
		
		if(subject.value == ""){
			alert("主题不能为空！");
			return false;
		}
		if(linkman.value == ""){
			alert("联系人不能为空！");
			return false;
		}
		if(contactWayId.value == "0"){
			alert("请选择本次联系方式！");
			return false;
		}
		if(contactDate.value == ""){
			alert("本次联系日期不能为空！");
			return false;
		}
		if(contactTime.value == "0"){
			alert("请选择本次联系时间！");
			return false;
		}
		
		if(nextContactDate.value != ""){
			if(nextContactTime.value == "0"){
				alert("请选择下次计划联系时间！");
				return false;
			}
			if(nextContactWayId.value == "0"){
				alert("请选择下次联系方式！");
				return false;
			}
		}
		
		if(contactDate.value != "" && currentDate.value != ""){
			var d1 = "";
			var d2 = "";
			d1 = (contactDate.value).replace("-","/");
			d2 = (currentDate.value).replace("-","/");
			if(Date.parse(d1) - Date.parse(d2) > 0){
				alert("本次联系日期不能大于当前系统日期！");
				return false;
			}
		}
		
		if(contactDate.value != "" && nextContactDate.value != ""){
			var d1 = "";
			var d2 = "";
			d1 = (contactDate.value).replace("-","/");
			d2 = (nextContactDate.value).replace("-","/");
			if(Date.parse(d1) - Date.parse(d2) > 0){
				alert("下次计划联系日期不能小于本次联系日期！");
				return false;
			}
			
			if(Date.parse(d1) - Date.parse(d2) == 0){
				if(contactTime.value == nextContactTime.value){
					alert("下次联系计划日期时间不能等于本次联系日期时间！");
					return false;
				}
			}
		}
		
		if(requireDesc.value == ""){
			alert("本次联系记录不能为空！");
			return false;
		}
		return true;
		
	}

	/**function back(){
		window.location.href = "./customerManage.do";
		window.location.target = "main";
	}*/
	
	function back(){
		var sign = "<c:out value='${sign}'/>";
		if(sign == '2'){
			uri = "./saleRecord.do";//返回销售日志页面
		}else {
			uri = "./customerManage.do";//返回客户资料页面
		}
		window.location.href = uri;
		window.location.target = "main";
	}
	
	function linkmanDialog(){
		var customerId = document.getElementById("customerId");
		if(customerId.value != ""){
			var customerId = document.getElementById("customerId").value;
			var url = "./saleRecord.do?action=selectLinkman&customerId="+customerId+"&radom="+<%=r.nextInt(100)%>;
			var dlgParam = "dialogHeight:350px;dialogWidth:300px;dialogTop:300px;dialogLeft:400px;status:no;help:no;scrollbars:yes;";
			var rt = window.showModalDialog(url,"",dlgParam);
			if(rt != undefined){
				//根据从子窗口得到的值，从中提取联系人id、联系人名称
				var linkmanId = "";
				var linkmanName = "";
				var linkmanDeptId = "";
				var tStr = rt.split(",");
				if(tStr[0] != "" && tStr[1] != ""){
					linkmanId = tStr[0];
					linkmanName = tStr[1];
					linkmanDeptId = tStr[2];
				}
				document.getElementById("linkmanId").value = linkmanId;	
				document.getElementById("linkman").value = linkmanName;
				document.getElementById("linkmanDeptId").value = linkmanDeptId;
			}
		}
		/**else{
			alert("请选择客户！");
		}*/
	}
	
	function save(){
		if(checkForm()){
			document.addCustomerHangupForm.action = "./saleRecord.do?action=addSaleRecordHangup";
			document.addCustomerHangupForm.target = "main";
			document.addCustomerHangupForm.submit();
		}
	}
	
	function initPage(result){
		if(result == 1){
			alert("保存成功！");
		}else if(result == 2){
			alert("上传失败：文件不能为空!");
		}else if(result == 3){
			alert("上传失败：文件大小不能超过10M!");
		}else if(result == 4){
			alert("上传失败：请勿重复上传附件!");
		}
		
		if("<c:out value='${saleRecord.requireDesc}'/>" == ""){
			document.getElementById("requireDesc").value = "联系目的：\n\n人员及背景：\n\n联系过程：\n\n分析：\n\n概率及原因：\n\n下一步：\n\n请求支持：";
		}
	}
	
-->
</script>
</head>
<body onload="initPage('${result}')">
<form name="addCustomerHangupForm" action="" method="post" enctype="multipart/form-data">
	<table class="table_frame">
		<tr>
			<td>
				<table class="table_title1">
					<tr>
						<td class="title_lab">商机挂起记录</td>
					</tr>
					<tr>
						<td align="center" valign="bottom">
							<button class="btn_submit" onclick="save()" hidefocus="true">保存</button>&nbsp;&nbsp;
							<button class="btn_back" onclick="back()" hidefocus="true">取消并返回</button>
						</td>
					</tr>
					<tr><td height="2"></td></tr>
				</table>
			</td>
		</tr>
		<tr>
			<td>
				<table class="table_title2">
					<tr>
						<td>
							<table class="table_add">
								<tr><td colspan="2" class="title_top">日志信息</td></tr>
								<tr>
									<td class="title">客户名称：</td>
									<td>
										${customer.customerName}
										<input id="customerId" name="customerId" type="hidden" value="${customer.id}"/>
										<input id="currentUserId" name="currentUserId" type="hidden" value="${userId}"/>
									</td>
								</tr>
								<tr>
									<td  class="title"><font color="red">*</font>&nbsp;&nbsp;主题：</td>
									<td><input id="subject" name="subject" class="input_long" type="text" value="${saleRecord.subject}"/></td>
								</tr>
								<tr>
									<td  class="title"><font color="red">*</font>&nbsp;&nbsp;联系人：</td>
									<td>
										<input id="linkman" name="linkman" class="input_long" type="text" value="${saleRecord.linkman}"/>&nbsp;
										<input class="btn_select" type="button" value="" onclick="linkmanDialog()" hidefocus="true"/>
										<input id="linkmanId" name="linkmanId" type="hidden" value="${saleRecord.linkmanId}"/>
										<input id="linkmanDeptId" name="linkmanDeptId" type="hidden" value="${saleRecord.linkmanDeptId}"/>
									</td>
								</tr>
								<tr>
									<td class="title"><font color="red">*</font>&nbsp;&nbsp;本次联系方式：</td>
									<td>
										<select id="contactWayId" name="contactWayId">
											<option value="0" <c:if test='${saleRecord.contactWayId == 0}'>selected</c:if> >--------请选择--------</option>
											<c:forEach var="contactWay" items="${contactWays}">
											<option value="${contactWay.id}" <c:if test='${saleRecord.contactWayId == contactWay.id}'>selected</c:if> >${contactWay.rangeValue}</option>
											</c:forEach>
										</select>
									</td>
								</tr>
								<tr>
									<td class="title"><font color="red">*</font>&nbsp;&nbsp;本次联系时间：</td>
									<td>
										<input id="contactDate" name="contactDate" class="input_long" type="text" 
											onclick="calendar(this,'yyyy-MM-dd');" readonly="readonly" value="${saleRecord.contactDate}"/>
										<select id="contactTime" name="contactTime">
											<option value="0" <c:if test='${saleRecord.contactTime == 0}'>selected</c:if> >---请选择---</option>
											<option value="1" <c:if test='${saleRecord.contactTime == 1}'>selected</c:if> >上午</option>
											<option value="2" <c:if test='${saleRecord.contactTime == 2}'>selected</c:if> >下午</option>
										</select>
									</td>
								</tr>
								<tr>
									<td class="title1">下次计划联系时间：</td>
									<td>
										<input id="nextContactDate" name="nextContactDate" class="input_long" type="text" 
											onclick="calendar(this,'yyyy-MM-dd');" readonly="readonly" value="${saleRecord.nextContactDate}"/>
										<select id="nextContactTime" name="nextContactTime">
											<option value="0" <c:if test='${saleRecord.nextContactTime == 0}'>selected</c:if> >---请选择---</option>
											<option value="1" <c:if test='${saleRecord.nextContactTime == 1}'>selected</c:if> >上午</option>
											<option value="2" <c:if test='${saleRecord.nextContactTime == 2}'>selected</c:if> >下午</option>
										</select>
									</td>
								</tr>
								<tr>
									<td class="title1">下次联系方式：</td>
									<td>
										<select id="nextContactWayId" name="nextContactWayId">
											<option value="0" <c:if test='${saleRecord.nextContactWayId == 0}'>selected</c:if> >--------请选择--------</option>
											<c:forEach var="contactWay" items="${contactWays}">
											<option value="${contactWay.id}" <c:if test='${saleRecord.nextContactWayId == contactWay.id}'>selected</c:if> >${contactWay.rangeValue}</option>
											</c:forEach>
										</select>
									</td>
								</tr>
								<!-- 
								<tr>
									<td width="20%"><input type="checkbox"/>下次提醒：</td>
									<td>
										提前：
										<select>
											<option>--------请选择--------</option>
										</select>
									</td>
								</tr>
								 -->
								<tr>
									<td class="title"><font color="red">*</font>&nbsp;&nbsp;本次联系记录：</td>
									<td><textarea id="requireDesc" name="requireDesc" class="textarea_desc" wrap="hard">${saleRecord.requireDesc}</textarea></td>
								</tr>
								<tr>
									<td class="title"><font style="font-size: 10px;">(附件 &lt; 10M)</font>&nbsp;&nbsp;上传附件：</td>
									<td>
										<input id="contents" name="contents" type="file" style="width: 85%" value="${saleRecord.contents}"/>
									</td>
								</tr>
								<!-- 
								<tr>
									<td width="">产品报价：</td>
									<td><input id="productPrice" name="productPrice" class="input_long" type="text" onkeyup="onlyNumFloat(this)" value="${saleRecord.productPrice}"/>元*</td>
								</tr>
								 -->
							</table>
						</td>
					</tr>
				</table>
			</td>
		</tr>
	</table>
	<input id="currentDate" name="currentDate" type="hidden" 
		value="<fmt:formatDate value='<%=new java.util.Date()%>' pattern="yyyy-MM-dd"/>"/>
	<input id="sign" name="sign" type="hidden" value="${sign}"/>
</form>	
</body>
</html>